package com.wn.portal;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerInterceptor;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @author yellow Docter
 * @date 2022 -08-22
 * @desc
 */
@EnableCircuitBreaker   // 开启服务熔断
@EnableFeignClients     // 开启 openFeign 客户端
@EnableEurekaClient
@SpringBootApplication  // 复合注解 （config、ComponentScan、import 三个功能）
public class PortalApplication {

    LoadBalancerInterceptor b;

    public static void main(String[] args) {

        SpringApplication.run(PortalApplication.class,args);
    }

    // 添加一个中间件

    /**
     * RestTemplate 这个中间件可以实现远程调用
     *    封装了 HTTP请求
     *
     * @LoadBalanced  可以自动实现负载均衡
     * @return
     */
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

}
